import {Component, Input, OnInit} from '@angular/core';
import {PermissionDetail} from "@shared/models/Permission";
import {TestData} from "@shared/utils/TestData";
import {api} from "@core/service/config/api";
import {PmMessage} from "@shared/models/PmMessage";
import {NzModalService} from "ng-zorro-antd/modal";
import {PmMessageDealDialog} from "@/app/pages/user/pm-req/deal-dialog/pm-message-deal.dialog";
import {NzModalRef} from "ng-zorro-antd/modal/modal-ref";
import {PmMessageService} from "@core/service/PmMessageService";

@Component({
  selector: 'bby-pm-req',
  templateUrl: './pm-message.component.html',
  styleUrls: ['./pm-message.component.scss']
})
export class PmMessageComponent implements OnInit {
  constructor(
    protected dialogService: NzModalService,
    public pmReqService: PmMessageService
  ) {
  }

  ngOnInit(): void {
    // this.checkItem(this.reqList[0])
  }

  checkItem(item: PmMessage) {
    let dialogObj: { dialog: NzModalRef | undefined } = {
      dialog: undefined
    }
    dialogObj.dialog = this.dialogService.create({
      nzTitle: item.fromName + '请求获取权限',
      nzWidth: '600px',
      nzContent: PmMessageDealDialog,
      nzComponentParams: {
        pmReqItem: item,
        dialogObj
      },
      nzFooter: null
      // nzOkText:'保存',
      // nzOnOk:(page)=>
      //   new Promise(resolve => {
      //     item.deal = true
      //     resolve()
      // })
    })
  }

  delItemClick(index: number) {
    let item = this.pmReqService.list[index]
    if (item.deal) {
      console.log('删除', item)
      this.pmReqService.delete(item.id)
      return;
    }
    this.dialogService.create({
      nzTitle: '删除信息',
      nzContent: '这条请求还没有被处理，是否确认删除？',
      nzOnOk: () => new Promise(resolve => {
        this.pmReqService.delete(item.id)
        this.pmReqService.list.splice(index, 1)
        resolve()
      })
    })
  }

  clearListClick() {
    this.pmReqService.list = []
  }
}
